﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IUserPointInfoService
    {
        IQueryable<UserPointInfo> GetUserPointInfos();
        UserPointInfo GetUserPointInfo(int id);
        void CreateUserPointInfo(UserPointInfo userPointInfo);
        void DeleteUserPointInfo(int id);
        void SaveUserPointInfo();
    }
    
    public class UserPointInfoService : IUserPointInfoService
    {
        private readonly IUserPointInfoRepository userPointInfoRepository;
        private readonly IUnitOfWork unitOfWork;
        public UserPointInfoService(IUserPointInfoRepository userPointInfoRepository, IUnitOfWork unitOfWork)
        {
            this.userPointInfoRepository = userPointInfoRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IUserPointInfoService Members

        public IQueryable<UserPointInfo> GetUserPointInfos()
        {
            var userPointInfos = userPointInfoRepository.GetAll();
            return userPointInfos;
        }

        public UserPointInfo GetUserPointInfo(int id)
        {
            var userPointInfo = userPointInfoRepository.GetById(id);
            return userPointInfo;
        }

        public void CreateUserPointInfo(UserPointInfo userPointInfo)
        {
            userPointInfoRepository.Add(userPointInfo);
            SaveUserPointInfo();
        }

        public void DeleteUserPointInfo(int id)
        {
            var userPointInfo = userPointInfoRepository.GetById(id);
            userPointInfoRepository.Delete(userPointInfo);
            SaveUserPointInfo();
        }

        public void SaveUserPointInfo()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}